# Contributor: Clayton Craft <clayton@craftyguy.net>
# Maintainer: Clayton Craft <clayton@craftyguy.net>
pkgname=rbutil
pkgver=1.5.1
pkgrel=1
pkgdesc="automated installer tool for Rockbox"
url="https://www.rockbox.org/wiki/RockboxUtility.html"
arch="all"
license="GPL-2.0-or-later"
makedepends="
	cmake
	libmspack-dev
	libusb-dev
	qt5-qtbase-dev
	qt5-qtmultimedia-dev
	qt5-qtsvg-dev
	qt5-qttools-dev
	quazip-dev
	samurai
	speexdsp-dev
	zlib-dev
"
source="
	https://git.rockbox.org/cgit/rockbox.git/snapshot/rockbox-rbutil_$pkgver.tar.gz
	0001-rbutil-fix-compilation-on-non-glibc-Linux-systems.patch
	rbutil-1.5.1-system-quazip.patch
	no_qt6.patch
"
builddir="$srcdir/rockbox-rbutil_$pkgver"

prepare() {
	default_prepare

	sed '/add_subdirectory(themeeditor)/d' -i utils/CMakeLists.txt
	# force use of system libs:
	rm -r utils/rbutilqt/quazip
	rm -r utils/rbutilqt/zlib
}

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		local crossopts="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake -B build -G Ninja \
		-DBUILD_SHARED_LIBS=OFF \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_SKIP_RPATH=ON \
		-DUSE_SYSTEM_QUAZIP=ON \
		$crossopts \
		-Wno-dev \
		-S utils

	cmake --build build
}

check() {
	ctest --test-dir build --output-on-failure \
		-E TestHttpGet # tests broken
}

package() {

	install -Dm 755 build/rbutilqt/RockboxUtility \
		-t "$pkgdir"/usr/bin
	install -Dm 644 utils/rbutilqt/RockboxUtility.desktop \
		-t "$pkgdir"/usr/share/applications
	install -Dm 644 docs/logo/rockbox-clef.svg \
		-t "$pkgdir"/usr/share/pixmaps
}
sha512sums="
6f944b4127f9dce5836518334610b89d27c5ed459abedf427dba5c496d506ca93fa26a47b24e06725a818199162421ff9aba5ee7ec6589a80937a9203473ad43  rockbox-rbutil_1.5.1.tar.gz
ea8d85a087b6f68800eb2398090b60b8d53347491ef3054ecbd6c89004461cce3f9d092ddbaa0085c0b4c8a8748a87caa74636b927ae945dd33ec11f3f99bdc3  0001-rbutil-fix-compilation-on-non-glibc-Linux-systems.patch
3ee97efa7453ad7fc77a39dcae9225f1a17b176b62cde1033a3426d5f8786447d260a284f43b6fcf8bd7c8a5049f845a4241daa057ee81ad342d1994c83529d7  rbutil-1.5.1-system-quazip.patch
4dd4c48601951dbf6aea1b14fed0a6975b728d1cd6fba1ad6296c39675e33dbfda639b13edd3dc6d1684b438693f02143205480fb99e8329968e60d4854974a1  no_qt6.patch
"
